<?php
require './model/Db.php';
$Db = DB::getInstance();
$isMobile = preg_match('/mobile/i', $_SERVER['HTTP_USER_AGENT']);
$user_data = $Db->islogin();
$_GET = $Db->escape($_GET);
if($_GET['uid']>0){
	$isExist = $Db->find([
		table => ['bbs_user'],
		where => "`id` = {$_GET['uid']}"
]);
}
if($isExist){
	//用户身份
	if($isExist[0]['job'] == 3){
		$isExist[0]['job'] = '站务';
	}elseif($isExist[0]['job'] == 2){
		$isExist[0]['job'] = '区务';
	}elseif($isExist[0]['job'] == 1){
		$isExist[0]['job'] = '版务';
	}else{
		$isExist[0]['job'] = '普通用户';
	}
	//等级
	if($isExist[0]['lv']>=700){
		$lv = 'lv-7';
	}elseif($isExist[0]['lv']>=580){
		$lv = 'lv-6';
	}elseif($isExist[0]['lv']>=460){
		$lv = 'lv-5';
	}elseif($isExist[0]['lv']>=340){
		$lv = 'lv-4';
	}elseif($isExist[0]['lv']>=220){
		$lv = 'lv-3';
	}elseif($isExist[0]['lv']>=100){
		$lv = 'lv-2';
	}else{
		$lv = 'lv-1';
	}
	//获取关注和粉丝和版务
	$my_follow = json_decode($isExist[0]['my_follow'])->uids;
	$follow_me = json_decode($isExist[0]['follow_me'])->uids;
	$follow = count($my_follow);
	$fans = count($follow_me);
	if($isExist[0]['job'] != '站务'){
		$man_data = [];
		//版面
		$mids_arr = json_decode($isExist[0]['follow_me'])->mids;
		$man_mids = implode(',', $mids_arr);
		$man_module = $Db->find([
			table => ['module'],
			field => 'id,name',
			where => "id in ($man_mids)"
		]);
		if($man_module){
			foreach ($man_module as $mk => $man_mv) {
				$man_data['module'][$mk] = $man_mv;
			}
		}
		//区面
		$zids_arr = json_decode($isExist[0]['follow_me'])->zids;
		$man_zids = implode(',', $zids_arr);
		$man_zone = $Db->find([
			table => ['zone'],
			field => 'id,name',
			where => "id in ($man_zids)"
		]);
		if($man_zone){
			foreach ($man_zone as $zk => $man_zv) {
				$man_data['zone'][$zk] = $man_zv;
			}
		}
	}

	//获取发帖数
	$count = $Db->count([
		table => ['content'],
		where => "`uid` = {$_GET['uid']}"
	]);
	//获取我的关注
	if($user_data){
		$uids_arr = json_decode($user_data['my_follow'])->uids;
		$fol_class = in_array($isExist[0]['id'], $uids_arr)?' followed':'';
		$fol_title = in_array($isExist[0]['id'], $uids_arr)?'已关注':'未关注';
	}
	//状态
	$stat = (time()-$isExist[0]['last_time'])<1800 ? 'online':'offline';
}else{
	header('Location:err.php?id=3');
}
$Db->close();
$web_title = '用户信息：'.$isExist[0]['user'];
$css = [
	'public/css/my-bootstrap.min.css',
	'public/css/userinfo.all.min.css'
];
include './view/header.html';
include './view/userinfo.all.html';
include './view/footer.html';